﻿/*-----------------------------------------------------------------------------!
! GetConnectionString class                                                    !
!------------------------------------------------------------------------------!
! System   : Inventory Management System                                       !
! Client   : UK based                                                          !
! Date     : April 2011                                                        !
! Copyright: (C) KAWISOFT Inc                                                  !
! Program  : GetConnectionString.cs                                            !
! Function : get connection string from config file                            !
!------------------------------------------------------------------------------!
! Notes:                                                                       !
! Original author: Md. Shaiful Islam                                           !
! Last changed by: Md. Shaiful Islam, May 01 2011                              !
===============================================================================*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;


namespace Model.Sohaok
{
    public class GetConnectionString
    {
        private static GetConnectionString _instance = null;
        private static string PATH_CONFIG_FILE = "";
        private static string FILE_NAME = "\\Config.txt";
        private static string conn_str = "";

        protected GetConnectionString()
        {
            try
            {
                string startupPath = System.IO.Directory.GetCurrentDirectory();
                PATH_CONFIG_FILE = startupPath + FILE_NAME;
                var data = new Dictionary<string, string>();
                // read database information from config file
                foreach (var row in File.ReadAllLines(PATH_CONFIG_FILE))
                    data.Add(row.Split('=')[0], row.Split('=')[1]);

                // forming connection string
                conn_str = "Data Source=" + data["IP"] + "\\SQLEXPRESS;" +
                           "Integrated Security=SSPI;" +
                           "Initial Catalog=" + data["DbName"] + ";";
            }
            catch (Exception e)
            {

            }

        }


        public static string Instance()
        {
            if (_instance == null)
            {
                _instance = new GetConnectionString();
            }
            return conn_str;
        }

    }
}
